package hongcaosp.app.android.contact;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import hongcaosp.app.android.R;
import hongcaosp.app.android.common.BaseHolder;
import hongcaosp.app.android.contact.friends.OnFriendClickListener;
import hongcaosp.app.android.modle.bean.IUser;
import xlj.lib.android.base.utils.GlideUtils;
import xlj.lib.android.base.view.CircleImageView;

public class ContactHolder extends BaseHolder<IUser> {
    private Context context;
    private ImageView userLogoIV;
    private TextView userNameTV,desTV;
    private OnFriendClickListener friendClickListener;

    public ContactHolder(Context context, View itemView, OnFriendClickListener friendClickListener) {
        super(itemView);
        this.context = context;
        userLogoIV = itemView.findViewById(R.id.user_logo);
        userNameTV = itemView.findViewById(R.id.user_name);
        desTV = itemView.findViewById(R.id.des_tv);
        this.friendClickListener = friendClickListener;
        itemView.findViewById(R.id.message_btn).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (ContactHolder.this.friendClickListener != null) {
                    ContactHolder.this.friendClickListener.onMessageClick(getData());
                }
            }
        });

        itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (ContactHolder.this.friendClickListener != null) {
                    ContactHolder.this.friendClickListener.onItemClick(getData());
                }
            }
        });
    }

    @Override
    public void setData(IUser o) {
        super.setData(o);
        GlideUtils.loadCircleImage(context,o.getUserLogo(),userLogoIV,R.drawable.icon_head);
        userNameTV.setText(o.getUserName());
        if (!TextUtils.isEmpty(o.getUserComment())) {
            desTV.setVisibility(View.VISIBLE);
            desTV.setText(o.getUserComment());
        } else {
            desTV.setVisibility(View.GONE);
        }

    }
}
